mui.init({
	swipeBack:false //右滑关闭功能
});
if(window.plus){
    plusReady();
}else{
    document.addEventListener('plusready',plusReady,true);
}
function plusReady(){
   document.getElementById("jedw").innerText="万元";
   getQueryData();
   //返回首页
   document.getElementById('home').addEventListener('tap', function() {
	    var h=plus.webview.getWebviewById('mainpage');
	    plus.webview.show(h);
	    mui.fire(h,'tabClick',{tabId:'defaultTab'});
   });
   var dDate = new Date();
   //选择日期
   document.getElementById("btncxqj").addEventListener('tap', function() {
	    //dDate.setFullYear(2014, 7, 16);
	    plus.nativeUI.pickDate(function(e) {
	    	var d = e.date;
	    	var dataa =d.getFullYear() +"" + ((d.getMonth() + 1)<10?"0"+(d.getMonth() + 1):(d.getMonth() + 1) );
	    	document.getElementById("cxqj").innerText=dataa;
	    	getQueryData(dataa)
	    }, function(e) {
	    	//info.innerText = "您没有选择日期";
	    }, {
	    	title: "请选择日期",
	    	date: dDate
	    	});
	});
	mui("#pan_table_div").off("tap","pan_table_tr");      
	mui("#pan_table_div").on('tap','.pan_table_tr',function(){
    	if($(this).hasClass("backcolor")){
	        var tds=$(this).find("td");
	        selectxmbh=tds[1].innerText+"-"+tds[2].innerText;
	        mui.openWindow({url:"query_hblrjlrfp.html",id:"query_hblrjlrfp",extras:{selectxmbh:selectxmbh},waiting:{autoShow:false}});
    	}else{
    	    $(this).addClass("backcolor").siblings("tr").removeClass("backcolor");
		    $(this).siblings("tr").find("td").removeClass("backcolor_font");
	        $(this).find("td").addClass("backcolor_font");
    	}
    });  
}
function getQueryData(selectqj){
	var token = plus.storage.getItem("token");
	if(token==null||token==""){
		return;
	}else{
	   panUtil.ajaxLoding.start();
	   mui.ajax(baseServerAdrr+'/query/getLrfpList',{
	   data: {
	   		token:token,
	   		qj:selectqj
	   },
	   dataType:'json',//服务器返回json格式数据
	   type:'post',//HTTP请求类型
	   timeout:30000,//超时时间设置为10秒；
	   success:function(data){
		    panUtil.ajaxLoding.stop();
		    document.getElementById("cxqj").innerText=data.lastmonth;
		    if(data.code=='success'){
		    	initTable(data.message);
		    }else{
		    	mui.toast(data.message);
		    }
	   },
	   error:function(xhr,type,errorThrown){
		   //异常处理；
		   panUtil.ajaxLoding.stop();
		   mui.toast('服务器异常登录失败! query_lrfp');
	   }
	  });
	}
}
function initTable(data){
	var th="<tr><th width=\"30px\">序号</th><th width=\"30px\" style=\"display:none\">项目编号</th><th width=\"90px\">项目</th><th width=\"60px\">本月数</th><th width=\"60px\">本年累计数</th>"+
	           "<th width=\"60px\">上年同期数</th></tr>";
	var table=th;
	for(var i=0;i<data.length;i++){
		var td="";
		if(i==0){
			td=td+"<tr class=\"pan_table_tr backcolor\">";
		}else{
			td=td+"<tr class=\"pan_table_tr\">";

		}
		td=td+"<td class=\"pan_table_xh\">"+(i+1)+"</td>";
		td=td+"<td style=\"display:none\">"+data[i].hzd_orde+"</td>";
		td=td+"<td class=\"pan_table_td_left\">"+data[i].dyzd_sj.replace(new RegExp(' ', 'g'),"&nbsp;&nbsp;")+"</td>";

		var bylr=data[i].bylr;
		var bnlj=data[i].bnlj;
		var sntq=data[i].sntq;
		if(bylr<0){td=td+"<td class=\"pan_table_td_right\">-"+panUtil.fmoney(Math.abs(bylr)/10000,2)+"</td>";
		}else{td=td+"<td class=\"pan_table_td_right\">"+panUtil.fmoney(bylr/10000,2)+"</td>";}
		if(bnlj<0){td=td+"<td class=\"pan_table_td_right\">-"+panUtil.fmoney(Math.abs(bnlj)/10000,2)+"</td>";
		}else{ td=td+"<td class=\"pan_table_td_right\">"+panUtil.fmoney(bnlj/10000,2)+"</td>";	
		}if(sntq<0){
			td=td+"<td class=\"pan_table_td_right\">-"+panUtil.fmoney(Math.abs(sntq)/10000,2)+"</td>";
		}else{  td=td+"<td class=\"pan_table_td_right\">"+panUtil.fmoney(sntq/10000,2)+"</td>";	}
		td=td+"</tr>";
		table=table+td;
	}
	var tablediv=document.getElementById('pan_table');
	tablediv.innerHTML=table;
	
	
}

